<template>
	<view>
		<view
			style="height: 160rpx;box-sizing:border-box; padding-top: 81rpx;border-bottom: 2rpx solid #F7F7F7;display: flex;">
			<image src="/static/shequ/fh.png" @click="backTo()"
				style="margin: 0 259rpx 0 30rpx; width: 18rpx;height: 32rpx;" mode="aspectFit"></image>
			<text style="font-size: 32rpx;">收货地址</text>
		</view>
		<view style="margin: 0 30rpx;width: 690rpx;">
			<view class="xinxi">
				<text>收货人</text>
				<input type="text" value="" placeholder="请填写收货人" placeholder-style="font-size: 28rpx;"
					style="width: 167rpx;" v-model="name" />
			</view>
			<view class="xinxi">
				<text>手机号码</text>
				<input type="text" value="" placeholder="请填写电话" placeholder-style="font-size: 28rpx;"
					style="width: 168rpx;" v-model="phone" />
			</view>
	
			<view class="xinxi">
				<text>详细地址</text>
				<textarea v-model="val" style="font-size: 28rpx;width: 500rpx;height: 80rpx;" />
			</view>
		</view>
		<button type="default"
			style="width: 690rpx;height: 90rpx;background-color: #00C657;border-radius: 45rpx;position: fixed;bottom: 40rpx;left: 30rpx;color: #fff;font-size: 28rpx;display: flex;align-items: center;justify-content: center;"
			@click="getInfo">添加新地址</button>
	</view>
</template>

<script>
	import {
		Storage
	} from "@/static/libs/utils"
	export default {
		data() {
			return {
				val: '', //详细地址
				name: '', //收件人
				phone: '', //手机号
				token: '',
				lat: '',
				lng: ''
			};
		},
		onLoad(option) {
			if (option.id) {
				var info = option;
				this.name = decodeURIComponent(info.realname);
				this.phone = info.mobile;
				this.val = decodeURIComponent(info.address);
			}
			this.token = Storage.get('token');
			this.lat = Storage.get('latitude');
			this.lng = Storage.get('longitude');
		},
		methods: {
			getInfo() {
				// 添加、修改地址
				this.$request.post(
						`/waimai_go/app/wxapp.php?i=1&v=undefined&m=we7_wmall&c=entry&do=mobile&ctrl=wmall&ac=member&op=address&ta=post&&from=wxapp&state=${this.token}`, {
							realname: this.name, //联系人
							address: this.val, //地址
							mobile: this.phone, //电话
							sex: '男',
							number: '111',
							location_x: this.lat,
							location_y: this.lng
						})
					.then(res => {
						console.log(res);
						this.backTo();
						if (res.statusCode == 200) {
							uni.showToast({
								icon: "success",
								title: "添加成功"
							})
						};
					})
			}
		}
	}
</script>

<style lang="scss">
	.xinxi {
		margin: 39rpx 0 47rpx 0;
		display: flex;
		border-bottom: 1rpx solid #EEEEEE;
		padding-bottom: 41rpx;
		font-size: 28rpx;
		align-items: center;
		justify-content: space-between;
	}
</style>
